package lx11_TCP协议;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        //Tcp协议 ，接收数据
        //服务器端
        ServerSocket ss = new ServerSocket(8090);

        //等待客户端的连接
        Socket sc = ss.accept();

        //从连接通道中获取输入流
        //字节流（读中文会乱码）
        InputStream is = sc.getInputStream();
        //字符流
        InputStreamReader ist = new InputStreamReader(is);
        //缓冲流
        BufferedReader br = new BufferedReader(ist);
        
        char[] c = new char[1024];
        int len = -1;
        while((len = br.read(c)) != -1) System.out.print(new String(c,0,len));

        is.close();
        sc.close();
        ss.close();
    }
}
